using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;

namespace SmartPart
{
    public class AJAXConnectionData
    {
        private object _data;
        System.Collections.Generic.List<TriggerControl> _triggerControls;

        public AJAXConnectionData()
        {
            _triggerControls = new List<TriggerControl>();
        }

        public AJAXConnectionData(object data): this()
        {
            this.Data = data;
        }

        public AJAXConnectionData(object data, Control triggerControl, string triggerEvent): this(data)
        {
            this.TriggerControls.Add(new TriggerControl(triggerControl, triggerEvent));
        }

        public object Data
        {
            get { return _data; }
            set { _data = value; }
        }
        
        public System.Collections.Generic.List<TriggerControl> TriggerControls
        {
            get { return _triggerControls; }
            set { _triggerControls = value; }
        }

        public void RegisterTriggerControls(UpdatePanel updatePanel)
        {
            foreach (TriggerControl tc in TriggerControls)
            {
                AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
                trigger.ControlID = tc.Control.ID;
                trigger.EventName = tc.Event;
                updatePanel.Triggers.Add(trigger);
            }
        }
    }

    public class TriggerControl
    {
        private Control _control;
        private string _event;
        
        public TriggerControl(Control control, string controlEvent)
        {
            this.Control = control;
            this.Event = controlEvent;
        }

        public Control Control
        {
            get { return _control; }
            set { _control = value; }
        }

        public string Event
        {
            get { return _event; }
            set { _event = value; }
        }	
    }
}
